<template>
	<view class="container">
		<view class="item_class">
			<view>火灾报警</view>
			<view class="buttom_view">
				<button class="button_class" @click="toAlarm('烟火预警','0')">不播放广播</button>
				<button class="button_class" @click="toAlarm('烟火预警','1')">播放广播</button>
			</view>
		</view>
		<view class="item_class">
			<view>区域人员报警</view>
			<view>
				<button class="button_class" @click="toAlarm('人员密度','0')">不播放广播</button>
				<button class="button_class" @click="toAlarm('人员密度','1')">播放广播</button>
			</view>
		</view>
		<view class="item_class">
			<view>人脸报警</view>
			<view>
				<button class="button_class" @click="toAlarm('人脸识别')">人脸报警</button>
			</view>
		</view>
		<view class="item_class">
			<view>车辆报警</view>
			<view>
				<button class="button_class" @click="toAlarm('车牌识别')">车辆报警</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		methods: {
			toAlarm(alarmType, broadcast) {
				uni.showModal({
					title: "是否报警？",
					success: (res) => {
						if (res.confirm) {
							this.alarmInfo(alarmType, broadcast)
						}
					}
				})
			},
			alarmInfo(alarmType, broadcast) {
				let params = {}
				if (alarmType == "烟火预警") {
					params = {
						"type": "烟火预警",
						"deviceName": "乐至防火摄像头",
						"deviceIp": "192.168.102.206",
						"devicePort": "8000",
						"deviceUname": "admin",
						"deviceUpwd": "lzgd12345",
						"deviceProtocol": "海康SDK",
						"trackTime": 1639847302767,
						"sceneImage": "https://cdjjyl.com.cn/images/map/fanghuo.png",
						"alarmInfo": "旧居村铁塔处防火摄像头监控到附近有有火源燃烧，请立刻处理！",
						"areaCode": "2021030891230011",
						"broadcast": broadcast
					}
				} else if (alarmType == "人员密度") {
					params = {
						"deviceName": "乐至人流摄像头",
						"deviceIp": "192.168.102.205",
						"devicePort": "8000",
						"deviceUname": "admin",
						"deviceUpwd": "lzgd12345",
						"deviceProtocol": "海康SDK",
						"sceneImage": "https://cdjjyl.com.cn/images/map/renliu.png",
						"regionName": "劳动场镇社区路口",
						"alarmInfo": "劳动场镇社区路口人员过于密级，请相关人员立刻处理。",
						"type": "人员密度",
						"peopleCountNum": 100,
						"areaCode": "2021030891230011",
						"trackTime": 1639847302767,
						"channelName": "",
						"channelId": "1",
						"broadcast": broadcast
					}
				} else if (alarmType == "人脸识别") {
					params = {

					}
				} else if (alarmType == "车牌识别") {
					params = {

					}
				}
				uni.request({
					url: this.$api.request.apiBaseUrl + "lezhiDevice/deviceAlarmPushH5",
					data: params,
					method: 'POST',
					success: (response) => {
						if (response.data.body.status.statusCode == "0") {
							this.$api.msg("报警成功")
						} else {
							this.$api.msg("报警失败")
						}
					},
					fail: (error) => {
						this.$api.msg("报警失败")
					},
				})
			},
		}
	}
</script>

<style scoped>
	page {
		background: #fff;
	}

	.container {
		width: 100vw;
		height: 100vh;
		overflow: hidden;
		background: #fff;
		padding: 20upx
	}

	.item_class {
		font-size: 16px;
		margin-top: 30upx;
	}


	.button_class {
		width: 80%;
		margin-top: 20upx;
		margin-left: 10%;
	}
</style>
